// I. Amazon.com (US)

// Search RegExp for Amazon PK is case-insensitive. However, the normalized PK
// is upper case. Thus the upperCase flag is passed into createPathRegexpHandler.
var AMAZON_PK_RE = new RegExp("^[A-Za-z0-9]{14}$");
var AMAZON_PROFILE_PK_RE = new RegExp("gp/pdp/profile/([A-Za-z0-9]{14})");

var amazonPkHandler = nodemapper.createFirstMatchHandler([
    nodemapper.createSomethingSlashUsernameHandler(
        "gp/pdp/profile/friends", "amazon.com",
        {keyName: "pk", upperCase: 1}),
    nodemapper.createPathRegexpHandler(
        "amazon.com", AMAZON_PROFILE_PK_RE,
        {keyName: "pk", upperCase: 1}),
    nodemapper.createSomethingSlashUsernameHandler(
        "rss/people", "amazon.com",
        {keyName: "pk", upperCase: 1})]);

nodemapper.registerDomain("amazon.com", {
     accountToSgn: { pk: ["amazon.com", AMAZON_PK_RE] },
     urlToGraphNode: amazonPkHandler,
     name: "Amazon.com"
   }
);

nodemapper.addSimpleHandler("amazon.com", "pk_to_profile",
                            "http://www.amazon.com/gp/pdp/profile/");
nodemapper.addSimpleHandler("amazon.com", "pk_to_friends",
                            "http://www.amazon.com/gp/pdp/profile/friends/");
nodemapper.addSimpleHandler("amazon.com", "pk_to_rss",
                            "http://www.amazon.com/rss/people/", "/reviews");

// II. Amazon international TLDs
var AMAZON_I18N_DOMAINS = ["amazon.co.uk", "amazon.co.jp", "amazon.ca",
                           "amazon.fr", "amazon.de"];

var pkToProfileHandler = function(domain) {
  // function used to wrap domain variable scope
  return function(pk) { return "http://www." + domain + "/gp/pdp/profile/" + pk; }
};

for (var i = 0; i < AMAZON_I18N_DOMAINS.length; i++) {
  var domain = AMAZON_I18N_DOMAINS[i];
  var urlToGraphNodeHandler = nodemapper.createPathRegexpHandler(
      domain,
      AMAZON_PROFILE_PK_RE,
      {keyName: "pk", upperCase: 1}
    );
  nodemapper.registerDomain(domain, {
          name: domain,
          urlToGraphNode: urlToGraphNodeHandler,
          accountToSgn: { pk: [domain, AMAZON_PK_RE] },
          pk_to_profile: pkToProfileHandler(domain)
        });
}

__END__

http://www.amazon.com/gp/pdp/profile/A2Q1GI13N0TVRC sgn://amazon.com/?pk=A2Q1GI13N0TVRC
http://www.amazon.com/gp/pdp/profile/A2Q1GI13N0tvrc sgn://amazon.com/?pk=A2Q1GI13N0TVRC
http://amazon.com/gp/pdp/profile/A2Q1GI13N0TVRC sgn://amazon.com/?pk=A2Q1GI13N0TVRC
http://amazon.com/gp/pdp/profile/friends/A2Q1GI13N0TVRC sgn://amazon.com/?pk=A2Q1GI13N0TVRC

http://www.amazon.co.uk/gp/pdp/profile/A2Q1GI13N0TVRC sgn://amazon.co.uk/?pk=A2Q1GI13N0TVRC
http://amazon.ca/gp/pdp/profile/A2Q1GI13N0TVRC sgn://amazon.ca/?pk=A2Q1GI13N0TVRC
http://amazon.fr/gp/pdp/profile/A2Q1GI13N0TVRC sgn://amazon.fr/?pk=A2Q1GI13N0TVRC
http://amazon.de/gp/pdp/profile/A2Q1GI13N0TVRC sgn://amazon.de/?pk=A2Q1GI13N0TVRC
http://amazon.co.jp/gp/pdp/profile/A2Q1GI13N0TVRC sgn://amazon.co.jp/?pk=A2Q1GI13N0TVRC

http://www.amazon.com/rss/people/A2Q1GI13N0TVRC/reviews  sgn://amazon.com/?pk=A2Q1GI13N0TVRC

profile(sgn://amazon.com/?pk=A2Q1GI13N0TVRC) http://www.amazon.com/gp/pdp/profile/A2Q1GI13N0TVRC

profile(sgn://amazon.co.uk/?pk=A2Q1GI13N0TVRC) http://www.amazon.co.uk/gp/pdp/profile/A2Q1GI13N0TVRC
profile(sgn://amazon.co.jp/?pk=A2Q1GI13N0TVRC) http://www.amazon.co.jp/gp/pdp/profile/A2Q1GI13N0TVRC
profile(sgn://amazon.ca/?pk=A2Q1GI13N0TVRC) http://www.amazon.ca/gp/pdp/profile/A2Q1GI13N0TVRC
profile(sgn://amazon.fr/?pk=A2Q1GI13N0TVRC) http://www.amazon.fr/gp/pdp/profile/A2Q1GI13N0TVRC
profile(sgn://amazon.de/?pk=A2Q1GI13N0TVRC) http://www.amazon.de/gp/pdp/profile/A2Q1GI13N0TVRC

rss(sgn://amazon.com/?pk=A2Q1GI13N0TVRC) http://www.amazon.com/rss/people/A2Q1GI13N0TVRC/reviews

http://www.amazon.com http://www.amazon.com
http://www.amazon.com/gp/pdp/profile/interesting/A2GS4P0VOJYU96 http://www.amazon.com/gp/pdp/profile/interesting/A2GS4P0VOJYU96
http://www.amazon.com/gp/history/ http://www.amazon.com/gp/history/
